﻿///////////////////////////////////////////////////////////////////////////////
//
// This file is part of the BassDrop project
//   https://code.google.com/p/bass-drop/
//
//
// Creator:	Gergely Krajcsovszki (krajcsovszkig@hotmail.com)
// Date:	2013-12-05 18:20
//
//
// Copyright © 2013-2014. Gergely Krajcsovszki
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
///////////////////////////////////////////////////////////////////////////////
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BassDrop.Core.Common.Media.Playlists;

namespace BassDrop.Core.Common.Data.IO
{
	/// <summary>
	/// Provides utility methods for playlist file handling, eg. reading, writing, validation, etc.
	/// </summary>
	public static class PlaylistIO
	{
		/// <summary>
		/// Returns the list of valid extensions of the supported playlist file formats beginning with a dot
		/// </summary>
		public static IEnumerable<string> PlaylistFileExtensions
		{
			get
			{
				yield return XplfIO.FileExtension; // TODO: többi
			}
		}

		/// <summary>
		/// Reads a supported playlist file from the passed Uri and returns it. The format is determined
		/// from the extension
		/// </summary>
		/// <param name="uri"></param>
		/// <returns></returns>
		public static Playlist Read( Uri uri )
		{
			// TODO: PlaylistIO pluginokkal, tetszőleges formátumokra
			// yet only xplf
			return XplfIO.Read( uri );
		}

		/// <summary>
		/// Writes a supported playlist file on the passed Uri from the passed Playlist. The format is determined
		/// from the extension.
		/// </summary>
		/// <param name="playlist"></param>
		/// <param name="uri"></param>
		/// <returns></returns>
		public static void Write( Playlist playlist, Uri uri )
		{
			lock ( ((ICollection) playlist).SyncRoot ) // TODO: helyette thread safe copy? vagy okosabb lock?
			{
				XplfIO.Write( playlist, uri );
			}
		}
	}
}
